class FoodServer {

  String ip;
  int FOOD_SERVER_PORT;
  PApplet theApplet;
  Server myServer;

  public FoodServer(PApplet theApplet) {
    this.theApplet = theApplet;
    FOOD_SERVER_PORT = 28000;
    startServer();
  }

  public void startServer()
  {
    myServer = new Server(theApplet, FOOD_SERVER_PORT);
  }


  public boolean readFromNetwork()
  {
    Client c = myServer.available();
    if (c != null)
    {
      String whatClientSaid = c.readString();
      String[] _data = split(whatClientSaid, ",");
      println(whatClientSaid);
      println(" ---> network read " + whatClientSaid.length());
      
      int id = Integer.parseInt(_data[1]);
      if( _data[0].compareTo("F") == 0 ) {
        int amount = Integer.parseInt(_data[2]); 
        sim.setFoodDishAmount(id, amount);
      }
      else if( _data[0].compareTo("W") == 0 ) {
        String sendString = "W," + id + "," + (sim.getFoodDishAmount(id) == 0 ? 0 : sim.getFoodDishAmount(id) - 1); 
        println("Sending: " + sendString );
        c.write(sendString);
      }

      //loadData( _data );
      return true;
    }
    else
    {
      // no connection, nothing updated
      return false;
    }
  }
}

